package com.opencee.boot.db.autoconfigure;

import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.opencee.boot.db.mybatis.injector.CustomizedSqlInjector;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * 配置类
 *
 * @author liuyadu
 */
@Slf4j
@Configuration
public class MybatisPlusAutoConfiguration {


    /**
     * 分页插件
     */
    @Bean
    @ConditionalOnMissingBean(PaginationInnerInterceptor.class)
    public PaginationInnerInterceptor paginationInterceptor() {
        PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
        paginationInterceptor.setMaxLimit(1000L);
        log.info("分页插件 [{}]", paginationInterceptor);
        return paginationInterceptor;
    }

    @Bean
    @Primary
    public DefaultEntityMetaObjectHandler entityMetaObjectHandler(){
        DefaultEntityMetaObjectHandler metaObjectHandler = new DefaultEntityMetaObjectHandler();
        log.info("实体自动填充类 [{}]", metaObjectHandler);
        return metaObjectHandler;
    }

    /**
     *
     * @return
     */
    @Bean
    public CustomizedSqlInjector customizedSqlInjector() {
        return new CustomizedSqlInjector();
    }
}
